package com.siwei.mes.entity.experiment.cement;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;

/**
 * @Description: 水泥-强度测定
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CementQdcd {
    @ApiModelProperty(value = "抗折强度试验-3d")
    private CementQdcd.Kzqdsy kzqdsy3d = new CementQdcd.Kzqdsy();
    @ApiModelProperty(value = "抗压强度试验-3d")
    private CementQdcd.Kyqdsy kyqdsy3d = new CementQdcd.Kyqdsy();
    @ApiModelProperty(value = "抗折强度试验-7d")
    private CementQdcd.Kzqdsy kzqdsy7d = new CementQdcd.Kzqdsy();
    @ApiModelProperty(value = "抗压强度试验-7d")
    private CementQdcd.Kyqdsy kyqdsy7d = new CementQdcd.Kyqdsy();
    @ApiModelProperty(value = "抗折强度试验-28d")
    private CementQdcd.Kzqdsy kzqdsy28d = new CementQdcd.Kzqdsy();
    @ApiModelProperty(value = "抗压强度试验-28d")
    private CementQdcd.Kyqdsy kyqdsy28d = new CementQdcd.Kyqdsy();
    @ApiModelProperty(value = "检测日期-3d")
    private String jcrq3d = "";
    @ApiModelProperty(value = "检测日期-7d")
    private String jcrq7d = "";
    @ApiModelProperty(value = "检测日期-28d")
    private String jcrq28d = "";


    @Data
    @Accessors(chain = true)
    @ApiModel("抗压强度试验信息")
    public static  class Kyqdsy {
        @ApiModelProperty(value = "抗压强度信息")
        private List<CementQdcd.KyqdsyInfo> kyqdsyInfo = Collections.singletonList(new CementQdcd.KyqdsyInfo());
        @ApiModelProperty(value = "抗压强度试验-28d")//1
        private String pjz = "";
        @ApiModelProperty(value = "抗压强度试验-28d")//1
        private String dxjl = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("抗折强度试验信息")
    public static class Kzqdsy {
        @ApiModelProperty(value = "抗折强度信息")
        private List<KzqdsyInfo> kzqdsyInfo = Collections.singletonList(new CementQdcd.KzqdsyInfo());
        @ApiModelProperty(value = "平均值")//1
        private String pjz = "";
        @ApiModelProperty(value = "单项结论")//1
        private String dxjl = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("抗折强度信息")
    public static class KzqdsyInfo {
        @ApiModelProperty(value = "荷载")
        private String hz = "";
        @ApiModelProperty(value = "距离")
        private String jl = "";
        @ApiModelProperty(value = "试件宽度")
        private String sjkd = "";
        @ApiModelProperty(value = "抗折强度")
        private String kzqd = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("抗压强度信息")
    public static class KyqdsyInfo {
        @ApiModelProperty(value = "荷载")
        private String hz = "";
        @ApiModelProperty(value = "受压面积")
        private String symj = "";
        @ApiModelProperty(value = "抗压强度")
        private String kyqd = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CementQdcd entity = new CementQdcd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CementQdcd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CementQdcd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CementQdcd entity = JsonUtils.getObject(objJson, CementQdcd.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }

        Kzqdsy kzqdsy3d = entity.getKzqdsy3d();
        Kzqdsy kzqdsy7d = entity.getKzqdsy7d();
        Kzqdsy kzqdsy28d = entity.getKzqdsy28d();

        Kyqdsy kyqdsy3d = entity.getKyqdsy3d();
        Kyqdsy kyqdsy7d = entity.getKyqdsy7d();
        Kyqdsy kyqdsy28d = entity.getKyqdsy28d();

        if (kzqdsy3d == null || kzqdsy7d == null || kzqdsy28d == null || kyqdsy3d == null || kyqdsy7d == null || kyqdsy28d == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        String msg = null;
        msg = checkKzqdsy(kzqdsy3d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        msg = checkKzqdsy(kzqdsy7d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        msg = checkKzqdsy(kzqdsy28d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        msg = checkKyqdsy(kyqdsy3d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        msg = checkKyqdsy(kyqdsy7d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        msg = checkKyqdsy(kyqdsy28d, name);
        if (StringUtils.isNotBlank(msg)) {
            return msg;
        }
        return null;
    }

    public static String checkKzqdsy(Kzqdsy kzqdsy, String name) {
        if (StringUtils.isBlank(kzqdsy.getPjz()) || "null".equals(kzqdsy.getPjz()) || StringUtils.isBlank(kzqdsy.getDxjl()) || "null".equals(kzqdsy.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static String checkKyqdsy(Kyqdsy kyqdsy, String name) {
        if (StringUtils.isBlank(kyqdsy.getPjz()) || "null".equals(kyqdsy.getPjz()) || StringUtils.isBlank(kyqdsy.getDxjl()) || "null".equals(kyqdsy.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

}
